package com.blog.cloud.dao;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.blog.cloud.comm.modal.pojo.BlogContent;
import com.blog.cloud.comm.webutils.CommMethod;
import com.jfinal.plugin.activerecord.Page;

public class BlogContentDao extends BlogContent {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6015657826684342617L;
	public static BlogContentDao me = new BlogContentDao();
	public String tabName = CommMethod.getTbaleName("BlogContent");
	
	
	public void insert(BlogContent blogContent){
		blogContent.save();
	}
	
	public void update(BlogContent blogContent){
		blogContent.update();
	}
	
	
	
	public List<BlogContent> geetBlogContentByUserNo(String userNo){
		String sql = "select * from "+tabName+ " where update_user_no = ?  ORDER BY update_time DESC ";
		return dao.find(sql, userNo);
	}
	
	
	
	public BlogContent geetBlogContentSerialId(String serialId){
		return dao.findById(serialId);
	}
	
	
	
	
	public Page<BlogContent> pageInint(String userNo , String searchVal , int pageNumber , int pageSize ){
		
		if(StringUtils.isNotEmpty(userNo)){
			String selectHead = " select * ";
			String selectBody = " from "+tabName+ " where update_user_no = ?  ";
			
			if(StringUtils.isNotEmpty(searchVal) && !"'".equals(searchVal)){
				selectBody += " and blog_title like '%"+searchVal+"%' ";
			}
			selectBody += " ORDER BY update_time DESC ";
			return dao.paginate(pageNumber, pageSize, selectHead, selectBody, userNo);
		}
		return null;
	}
	
	
}
